﻿using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using BakalarskaPraca.Generation.Data;
using BakalarskaPraca.Generation.Tasks;
using BakalarskaPraca.Generation.Tasks.Abstract;

namespace BakalarskaPraca.Forms.GenerationSettingsForms
{
    public partial class PlantGridDistributionSettingsForm : PlantGridDistributionSettingsFormBase
    {
        public PlantGridDistributionSettingsForm()
        {
            InitializeComponent();
        }

        public override bool ShowSettings(GridPositionPlantDistributionGeneration generationProcess)
        {
            this.numericTextBox1.IntValue = generationProcess.GridSize;
            this.numericTextBox2.IntValue = generationProcess.Variance;
            this.LibraryPathTB.Text = generationProcess.PlantLibrarySource;
            if (this.ShowDialog() == DialogResult.OK)
            {
                generationProcess.GridSize = this.numericTextBox1.IntValue;
                generationProcess.Variance = this.numericTextBox2.IntValue;
                generationProcess.PlantLibrarySource = this.LibraryPathTB.Text;
                return true;
            }
            return false;
        }

        public override GenerationProcess GetNewGenerationProcess(List<HumidityPolygon> polygons, ModelData modelData)
        {
            return new GridPositionPlantDistributionGeneration(polygons, modelData);
        }

        private void BrowseBtnClick(object sender, System.EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.LibraryPathTB.Text = this.openFileDialog1.FileName;
            }
        }

        private void PlantGridDistributionSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK && !File.Exists(this.LibraryPathTB.Text))
            {
                MessageBox.Show("File '" + this.LibraryPathTB.Text + "' does not exist.");
                e.Cancel = true;
            }   
        }
    }

    public class PlantGridDistributionSettingsFormBase : GenerationSettingsFormBase<GridPositionPlantDistributionGeneration> { }
}
